#!/bin/mksh

DRSR=$HOME/1drop/
IMGS=/mnt/toshstor/i/t/drop
SRTD=$HOME/1sort

f_wrap()
{
	[ ! -d "$3" ] && mkdir -p "$3"

	if [ $1 -eq 0 ]
	then
		find $DRSR -regextype posix-egrep -regex "$2" -exec mv -n -t "$3" {} +
	else
		find $DRSR -name "$2" -exec mv -n -t "$3" {} +
	fi

	return 0
}

# pictures
f_wrap 0 ".*\.(svg|tga|psd|bmp|gifv|webp)$"                   "$IMGS/random"
f_wrap 0 ".*\.(jpg|jpeg|jpe)$"                                "$IMGS/random/jpg"
f_wrap 1 "*.gif"                                              "$IMGS/random/gif"
f_wrap 1 "*.png"                                              "$IMGS/random/png"

# arch
f_wrap 0 ".*\.(tar|zip|7z|rar|gz|xz|bz2|tgz)$"                "$SRTD/archive"

# applications
f_wrap 0 ".*\.(deb|run|bin|rpm|sh|py)$"                       "$SRTD/run/linux"
f_wrap 0 ".*\.(diff|patch)$"                                  "$SRTD/run/linux/patches"
f_wrap 0 ".*\.(exe|msi)$"                                     "$SRTD/run/win"
f_wrap 1 "*.apk"                                              "$SRTD/run/android"
f_wrap 1 "*.jar"                                              "$SRTD/run/java"

# texts
f_wrap 0 ".*\.(pdf|djvu|txt|doc|docx|fb2|epub|rtf|mobi|ps)$"  "$SRTD/text"
f_wrap 0 ".*\.(html|htm|mht|mhtml|chm|maff)$"                 "$SRTD/pages"
f_wrap 0 ".*\.(c|cpp|ebuild|js|h)$"                           "$SRTD/sources"

# media
f_wrap 0 ".*\.(flv|mp4|avi|mkv|mov|webm|wmv)$"                "$SRTD/videos"
f_wrap 0 ".*\.(mp3|ogg|flac|sid|xm|wma|wav)$"                 "$SRTD/sound"
f_wrap 1 "*.swf"                                              "$SRTD/swf"

# mics
f_wrap 1 "*.torrent"                                          "$SRTD/tor"
f_wrap 1 "*.iso"                                              "$SRTD/iso"
f_wrap 1 "*.xpi"                                              "$SRTD/addons"
f_wrap 0 ".*\.(sqlite|csv|db)$"                               "$SRTD/db"
f_wrap 0 ".*\.(ttf|otf|woff|pcf|bdf)$"                        "$SRTD/fonts"

exit 0
